package kr.or.kosta.otr.persistence.company;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import kr.or.kosta.otr.vo.CompanyVO;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
@Repository("CompanyDao")
public class CompanyDaoImpl implements CompanyDao{
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;
	
	
	@Override
	public void addCompany(CompanyVO vo) throws SQLException {
		sqlMapClient.insert("Company.addCompany",vo);
	}

	@Override
	public void updateCompany(CompanyVO vo) throws SQLException {
		sqlMapClient.update("Company.updateCompany",vo);
	}

	@Override
	public void deleteCompany(int companyId) throws SQLException {
		sqlMapClient.delete("Company.deleteCompany", companyId);
	}

	@Override
	public CompanyVO getOneCompany(int companyId) throws SQLException {
		return (CompanyVO)sqlMapClient.queryForObject("Company.getOneCompany", companyId);
	}

	@Override
	public ArrayList<CompanyVO> getAllCompany() throws SQLException {
		return (ArrayList<CompanyVO>)sqlMapClient.queryForList("Company.getAllCompany");
	}

	@Override
	public ArrayList<CompanyVO> getCompanyByIndustry(String Industry)
			throws SQLException {
		return (ArrayList<CompanyVO>)sqlMapClient.queryForList("Company.getCompanyByIndustry", Industry);
	}

	@Override
	public ArrayList<CompanyVO> getCompanyByRegion(String region)
			throws SQLException {
		return (ArrayList<CompanyVO>)sqlMapClient.queryForList("Company.getCompanyByRegion", region);
	}

	@Override
	public ArrayList<CompanyVO> getCompanyInfo(HashMap<String,Object> map) throws SQLException {
		return (ArrayList<CompanyVO>) sqlMapClient.queryForList("Company.getCompanyInfo",map);
	}

	@Override
	public ArrayList<CompanyVO> getCompantBySalary(int salary)
			throws SQLException {
		return (ArrayList<CompanyVO>)sqlMapClient.queryForList("Company.getCompantBySalary", salary);
	}

	@Override
	public ArrayList<CompanyVO> getCompanyByTotalScore(int totalScore)
			throws SQLException {
		return (ArrayList<CompanyVO>)sqlMapClient.queryForList("Company.getCompanyByTotalScore", totalScore);
	}

	@Override
	public void setCompanyTotalScore(HashMap<String, Object> map)
			throws SQLException {
		
		sqlMapClient.delete("Company.setCompanyTotalScore", map);
	}

	@Override
	public CompanyVO checkCompany(HashMap<String, String> map)
			throws SQLException {
		
		return (CompanyVO) sqlMapClient.queryForObject("Company.checkCompany", map);
	}

	@Override
	public ArrayList<CompanyVO> customCompany(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
	
		return (ArrayList<CompanyVO>)sqlMapClient.queryForList("Company.customCompany", map);
	}

	@Override
	public CompanyVO getOneCompanyByName(String companyName)
			throws SQLException {
		// TODO Auto-generated method stub
		return (CompanyVO) sqlMapClient.queryForObject("Company.getOneCompanyByName",companyName);
	}

	//main
	@Override
	public int getTopScoreCompanyId() throws SQLException {
		return (int) sqlMapClient.queryForObject("Company.getTopScoreCompanyId");
	}
	
	@Override
	public int getTopCompanyIdInRegion() throws SQLException {
		return (int) sqlMapClient.queryForObject("Company.getTopCompanyIdInRegion");
	}
	
	@Override
	public int getTopCompanyIdInIndustry() throws SQLException {
		return (int) sqlMapClient.queryForObject("Company.getTopCompanyIdInIndustry");
	}
	
	@Override
	public CompanyVO getSimpleCompany(int companyId) throws SQLException {
		return (CompanyVO) sqlMapClient.queryForObject("Company.getSimpleCompany", companyId);
	}
	
	@Override
	public ArrayList<Integer> getAllCompanyId() throws SQLException {
		return (ArrayList<Integer>) sqlMapClient.queryForList("Company.getAllCompanyId");
	}

	@Override
	public ArrayList<CompanyVO> getCompanyInfoPage(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
		return (ArrayList<CompanyVO>) sqlMapClient.queryForList("Company.getCompanyInfoPage", map);
	}

	@Override
	public int getCompanyInfoTotal(HashMap<String, Object> map)
			throws SQLException {
		// TODO Auto-generated method stub
		return (int) sqlMapClient.queryForObject("Company.getCompanyInfoTotal", map);
	}
}
